package com.enen.service.impl;


import com.enen.mapper.ClazzMapper;
import com.enen.mapper.EmpMapper;
import com.enen.mapper.StudentMapper;
import com.enen.pojo.JobOption;
import com.enen.pojo.PeopleOption;
import com.enen.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public JobOption getEmpJobData() {
        /*
        list.stream()：将 list 转换为一个流（Stream），以便进行后续的流式操作。
        map(dataMap -> dataMap.get("pos"))：对流中的每个 Map 对象（即每条查询记录）进行映射操作，
        通过 dataMap.get("pos") 从 Map 中获取键为 "pos" 的值，这个值通常代表员工的职位。
        toList()：将映射后的结果收集到一个新的 List 中，最终得到一个包含所有职位的列表 jobList
         */
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public PeopleOption getClazzPeopleData() {
        List<Map<String,Object>> list = clazzMapper.countClazzPeopleData();
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new PeopleOption(clazzList, dataList);
    }
}
